package cn.Quartz.Scheduler;

import cn.Quartz.Listener.JobListenerShopJ;
import cn.Quartz.Listener.SchedulerListenerExample;
import cn.Quartz.Listener.TriggerListenerExample;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.impl.StdSchedulerFactory;

public class SchedulerInstance {

    private static volatile Scheduler sched;

    private SchedulerInstance() {
    }

    public static synchronized Scheduler getInstance() {
        if (sched == null) {
            try {
//                SchedulerFactory sf = new StdSchedulerFactory();
//                Scheduler sched = sf.getScheduler();
            SchedulerFactory schedulerFactory = new StdSchedulerFactory();
            sched = schedulerFactory.getScheduler();

                sched.getListenerManager().addSchedulerListener(new SchedulerListenerExample());
                sched.getListenerManager().addTriggerListener(new TriggerListenerExample());
                sched.getListenerManager().addJobListener(new JobListenerShopJ());

                sched = schedulerFactory.getScheduler();
            } catch (SchedulerException e) {
                e.printStackTrace();
            }
        }
        return sched;

    }
}
